

<div id="rbac_role_save">
    <form>
        <zrow>

            <zcol :md="6">
                <zinput label="角色名" name="name" :ctx="this"/>
            </zcol>
        </zrow>

        <zrow>
            <zcol :md="12">
                <div class="form-group">
                    <label>资源</label>
                    <div class="leveled-checkbox">
                        <div class="panel small-panel" v-for="r in  allRes">
                            <div class="panel-heading">
                                <label  class="checkbox-inline"><input type="checkbox" v-model="form.res" :value="r.id"/>{{r.name}}</label>
                            </div>
                            <div class="panel-body">
                                <label v-for="sub in  r.children" class="checkbox-inline"><input v-model="form.res"  type="checkbox" :value="sub.id">{{sub.name}}</label>
                            </div>
                        </div>
                    </div>
                </div>

            </zcol>
        </zrow>

        <a @click="submit" class="btn btn-primary">提交</a>
    </form>

</div>

<script>
    new Vue({
        el:'#rbac_role_save',
        mounted:function(){
            if(this.editData){
                copyProperty(this.editData , this.form)
            }
            this.state.status = 'mounted'

            var _this = this ;
            zhttp.get('rbac/resource/all').then(function (data) {
                var top = data.filter(function(v){ return v.pid == 0  });
                top.map(function(v){
                    var child = []
                    data.map(function(sub){
                        if(sub.pid == v.id){
                            child.push(sub)
                        }
                    })

                    v.children =  child
                    return v
                })
                _this.allRes = top
            })
        },
        data:{
            state:{
                status:''
            },
            allRes:[],
            form:{
                name:'',
                res:[]
            },
            validate:{
                name:[Va.required],
            },
            editData:<?=$data?>
        },
        methods:{
            submit:function(){

                if(!validateAll(this)){
                    return
                }

                var id = App.url().param('id') || '' ;

                zhttp.post('rbac/role/save?id='+id,this.form,function (d) {
                    if(d.code == 0){
                        success('操作成功')
                        //Loader.getDialog('rbac/role/save').close()
                        go('rbac/role/index')
                    }else{

                    }
                    return false ;
                })
            }
        }
    })
</script>